package com.tompai.datagather.thread;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * 中断线程池的某个任务.
 */
public class InterruptThread {

    public static void main(String[] args) throws InterruptedException {

        Thread interruptThread = new Thread(new MyThread(1));
        ScheduledFuture<?> t = ThreadPoolUtils.getInstance().getThreadPool().scheduleAtFixedRate(interruptThread,0,2,
                TimeUnit.SECONDS);

        MyThread interruptThread1 = new MyThread(2);
        ThreadPoolUtils.getInstance().getThreadPool().scheduleAtFixedRate(interruptThread1,0,2,
                TimeUnit.SECONDS);

        MyThread interruptThread2 = new MyThread(3);
        ThreadPoolUtils.getInstance().getThreadPool().scheduleAtFixedRate(interruptThread2,0,2,
                TimeUnit.SECONDS);
       
        
        Thread.sleep(5*1000);

		//终止正在运行的线程interruptThread
        t.cancel(true);
        while (true){

        }
    }

   
}